﻿using System;
using RazorEngine.Templating;

namespace TSharp.Core
{
    internal class TSharperLocatorActivator : IActivator
    {
        #region Fields

        private readonly IServiceLocator Locator;

        #endregion

        #region Constructor

        /// <summary>
        /// Initialises a new instance of <see cref="TSharperDelegateActivator"/>.
        /// </summary>
        /// <param name="locator">The activator delegate.</param>
        public TSharperLocatorActivator(IServiceLocator locator)
        {
            if (locator == null)
                throw new ArgumentNullException("locator");

            Locator = locator;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Creates an instance of the specified type.
        /// </summary>
        /// <param name="type">The type to create an instance.</param>
        /// <returns>The <see cref="ITemplate"/> instance.</returns>
        public ITemplate CreateInstance(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            return Locator.Get(type) as ITemplate;
        }

        #endregion
    }
}